<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./../vue/vue@2.6.12.js"></script>
</head>
<body>
    <div id="app">
        
        <div>
            <div>
                <label for="ID">id</label><input type="text" name="ID" id="ID" v-model="id">
            </div>
            <div>
                <label for="content">内容</label><input type="text" name="内容" id="content" v-model="content">
            </div>
            <div>
                <input type="button" value="添加" @click="add">
            </div>
            <div>
                <input type="button" value="插入" @click="insert">
            </div>
        </div>

        <ul>
            <li v-for="item in people" :key="item.id">
                <input type="checkbox" :name="item.name" :id="item.id">
                {{ ""+item.id+"---"+item.name }}
            </li>
        </ul>

    </div>
    
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                id: null,
                content: null,
                people: [
                    {id: 0, name: '小名'},
                    {id: 1, name: '小花'},
                    {id: 2, name: '小车'},
                    {id: 3, name: '小狗'},
                ]
            },
            methods: {
                add() {
                    if(this.id==null||this.content==null) return;
                    this.people.push({
                        id: this.id,
                        name: this.content
                    })
                },

                insert() {
                    this.people.unshift({
                        id: this.id,
                        name: this.content
                    })
                }
            }
        })
    </script>
</body>
</html>